<?php

namespace STAGE\StageBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TacheType extends AbstractType {

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('description', 'textarea')
                ->add('$dateLimite', 'date', array(
                    'widget' => 'single_text',
                    'input' => 'datetime',
                    'format' => 'dd/MM/yyyy',
                    'attr' => array('class' => 'date'),))
                ->add('users', 'entity', 
                        array('class' => 'STAGE\UserBundle\Entity\User', 'query_builder' => function(UserRepository $er) 
                {
                return $er->createQueryBuilder('e')
                        ->where('e.roles LIKE :encadreur')
                        ->setParameter('encadreur', '%ROLE_ENCADREUR%');
                ;
            }
                ))
                ->add('stage', 'collection', array('type' => new StageType(),
                    'allow_add' => true,
                    'allow_delete' => true,
                    'by_reference' => false,))

        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'STAGE\UserBundle\Entity\Tache'
        ));
    }

    /**
     * @return string
     */
    public function getName() {
        return 'stage_stagebundle_tache';
    }

}
